package com.shuoyue.ycgk.views.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.appcatch.SPUtils;
import com.shuoyue.ycgk.entity.MainAdv;
import com.shuoyue.ycgk.ui.course.info.CourseInfoActivity;
import com.shuoyue.ycgk.ui.estimate.EstimateScoreActivity;
import com.shuoyue.ycgk.ui.mok.MokDetailActivity;
import com.shuoyue.ycgk.ui.news.NewsInfoActivity;
import com.shuoyue.ycgk.ui.papergroups.groupcommon.PaperCommonInfoActivity;
import com.shuoyue.ycgk.ui.recruitment.newsinfo.RecurimentInfoActivity;
import com.shuoyue.ycgk.ui.shop.ShopInfoActivity;
import com.shuoyue.ycgk.utils.GlideUtil;
import com.shuoyue.ycgk.utils.SizeUtil;
import com.shuoyue.ycgk.views.ResizableImageView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * 开屏广告Dialog
 * Created by Forty'7 on 2019/8/17
 */

public class AdvertisementDialog extends Dialog {
    @BindView(R.id.img)
    ResizableImageView img;
    @BindView(R.id.close)
    ImageView close;
    private final Context mContext;
    MainAdv mainAdv;

    public AdvertisementDialog(@NonNull Context context) {
        super(context, R.style.dialog);
        this.mContext = context;
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = View.inflate(context, R.layout.dialog_advertisement, null);
        setContentView(view);
        ButterKnife.bind(this, view);
//        getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        getWindow().setLayout((SizeUtil.getScreenWidth(mContext) * 3) / 4, ViewGroup.LayoutParams.WRAP_CONTENT);
        getWindow().setGravity(Gravity.CENTER);

    }


    public void setImage(MainAdv path) {
        mainAdv = path;
//        Glide.with(mContext).load(path).placeholder(R.mipmap.img_loading_gray).into(img);
        GlideUtil.loadImage(mContext, path.getAdvertUrl(), img);
    }


    @OnClick({R.id.img, R.id.close})
    public void onClick(View view) {
        SPUtils.setPrefInt(mContext, "main_adv_id", mainAdv.getId());
        switch (view.getId()) {
            case R.id.img:
                switch (mainAdv.getProductType()) {
                    //1，课程，2图书，3习题包，4公告，5资讯，6模考，7估分，8考前冲刺
//                    case 1:
//                        mContext.startActivity(new Intent(mContext, CourseInfoActivity.class)
//                                .putExtra("id", mainAdv.getProductId()));
//                        break;
//                    case 2:
//                        PaperCommonInfoActivity.start(mContext, mainAdv.getProductId(), 1);
//                        break;
//                    case 3:
//                        mContext.startActivity(new Intent(mContext, ShopInfoActivity.class)
//                                .putExtra("id", mainAdv.getProductId()));
//                        break;
//                    case 4:
//
//                        break;


                    case 1:
                        mContext.startActivity(new Intent(mContext, CourseInfoActivity.class)
                                .putExtra("id", mainAdv.getProductId()));
                        break;
                    case 2:
                        mContext.startActivity(new Intent(mContext, ShopInfoActivity.class)
                                .putExtra("id", mainAdv.getProductId()));
                        break;
                    case 3:
                        PaperCommonInfoActivity.start(mContext, mainAdv.getProductId(), 1, -1);

                        break;
                    case 4:
                        mContext.startActivity(new Intent(mContext, RecurimentInfoActivity.class)
                                .putExtra("id", mainAdv.getProductId()));
                        break;
                    case 5:
                        mContext.startActivity(new Intent(mContext, NewsInfoActivity.class)
                                .putExtra("id", mainAdv.getProductId()));
                        break;
                    case 6:
                        mContext.startActivity(new Intent(mContext, MokDetailActivity.class)
                                .putExtra("id", mainAdv.getProductId()));
                        break;
                    case 7:
                        mContext.startActivity(new Intent(mContext, EstimateScoreActivity.class)
                                .putExtra("id", mainAdv.getId()));
                        break;
                }
                dismiss();
                break;
            case R.id.close:
                dismiss();
                break;
        }
    }
}
